package org.dyz.banana.listeners;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.kafka.support.KafkaHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

public class DemoListener {

    private static final Logger log= LoggerFactory.getLogger(DemoListener.class);

    /**
     * id:消费者的ID
     * topics：监听的topic（可以多个）
     * groupId：消费者所属的消费者组
     *
     */
    @KafkaListener(id = "demoListener", topics = "dyz-topic")
    public void listen(ConsumerRecord record, Acknowledgment ack,
                       @Header(KafkaHeaders.RECEIVED_TOPIC) String topic) {
        log.info("demoListener已在dyz-topic下消费以下消息 : "+topic);
        ack.acknowledge();
    }
}
